/**
 * Copyright (c) 2018 人人开源 All rights reserved.
 * <p>
 * https://www.renren.io
 * <p>
 * 版权所有，侵权必究！
 */

package io.renren.controller;

import com.google.common.collect.Maps;
import io.renren.common.utils.Result;
import io.renren.core.dto.LearnHomeBannerDTO;
import io.renren.core.dto.LearnHomeTipsDTO;
import io.renren.core.dto.LearnNewsDTO;
import io.renren.core.dto.LearnUserScoreDTO;
import io.renren.core.service.LearnHomeBannerService;
import io.renren.core.service.LearnHomeTipsService;
import io.renren.core.service.LearnNewsService;
import io.renren.core.service.LearnUserScoreService;
import io.renren.entity.UserEntity;
import io.renren.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * banner
 *
 */
@RestController
@RequestMapping("/api/me")
@Api(tags = "测试接口")
public class ApiMeController {

    @Autowired
    private LearnHomeBannerService learnHomeBannerService;
    @Autowired
    private LearnHomeTipsService learnHomeTipsService;
    @Autowired
    private LearnUserScoreService learnUserScoreService;
    @Autowired
    private UserService userService;

    @GetMapping("info")
    @ApiOperation(value = "获取用户me页信息")
    public Result<?> meInfo(HttpServletRequest request) {
        String wxId = request.getHeader("wxId");
        UserEntity user = userService.getByWxId(wxId);
        if (Objects.isNull(user)) {
            return new Result<>().error("用户信息错误！");
        }
        LearnUserScoreDTO userScoreDTO = learnUserScoreService.getByUserId(user.getId());
        if (Objects.isNull(userScoreDTO)) {
            userScoreDTO = new LearnUserScoreDTO();
            userScoreDTO.setUserId(user.getId());
            userScoreDTO.setUserPoint(0);
            userScoreDTO.setUserLearnScore(0);
        }
        return new Result<>().ok(MeInfo.builder()
                .userScore(userScoreDTO)
                .build());
    }

    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    @Builder
    public static class MeInfo {
        private LearnUserScoreDTO userScore;
    }

}